/** 
  Copyright (c) 2008, 2009 Claudio Imbrenda
  This program is released under the terms of the
  GNU GPL version 3 or later.
*/

package macchina.nastri;

import macchina.*;

/**
 *
 * @author the_nihilant
 */
public class ArrayNastro implements AdattatoreEntrata{
  
  private byte[] dati=null;
  int i=0;
  private boolean isloop=false;
  
  /** Creates a new instance of ArrayNastro. 
   * Only the 5 least significant bit of every byte will be returned.
   * @param d the byte[] containing the data.
   */
  public ArrayNastro(byte[] d) {
    if(d==null)
      throw new NullPointerException("ArrayNastro: byte[] cannot be null!");
    dati=d;
  }
  
  public byte read(){
    if(dati==null)return 32;
    if(i<dati.length)return (byte)(dati[i++]&0x1F);
    else if(isloop){
        i=0;
        return (byte)(dati[i++]&0x1F);
    }
    return 32;
  }

    public void setLoop(boolean v) {
        isloop=v;
    }

    public boolean isLoop() {
        return isloop;
    }
  
  
}
